//
//  ViewController.m
//  上下翻页
//
//  Created by yszy on 2016/11/18.
//  Copyright © 2016年 yszy. All rights reserved.
//

#import "ViewController.h"
#import "JCFlipPageView.h"
#import "JCFlipPage.h"

@interface ViewController ()<JCFlipPageViewDataSource>
@property (nonatomic, strong) JCFlipPageView *flipPage;
@property(nonatomic,assign)int  count;
@property(nonatomic,assign)NSInteger  index;

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    
    
    _count = 20;
    
    
    _flipPage = [[JCFlipPageView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height-66)];
    [self.view addSubview:_flipPage];
    
    _flipPage.dataSource = self;
    [_flipPage reloadData];
    
    
    [self btnSetUP];

    
}

-(void)btnSetUP
{
    //添加一个button
    UIButton *btn = [[UIButton alloc]init];
    
    //设置btn的内容 ：uinormal
    [btn setTitle:@"下一组" forState:UIControlStateNormal];
    //设置btn的字体
    btn.titleLabel.font = [UIFont systemFontOfSize:14];
    //设置btn的字体颜色
    [btn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
    //设置背景
    btn.backgroundColor = [UIColor colorWithWhite:0.9 alpha:1];
    //设置frame
    btn.frame = CGRectMake(50, 600, 0, 44);
    
    //自动适应
    [btn sizeToFit];
    
    [self.view addSubview:btn];
    
    //添加监听
    [btn addTarget:self action:@selector(Click) forControlEvents:UIControlEventTouchUpInside];
}

- (void)Click {
    _count += 20;
    [_flipPage reloadDataWithIndexPath:_index];
}





- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mar - JCFlipPageViewDataSource
- (NSUInteger)numberOfPagesInFlipPageView:(JCFlipPageView *)flipPageView
{
    return self.count;
}
- (JCFlipPage *)flipPageView:(JCFlipPageView *)flipPageView pageAtIndex:(NSUInteger)index
{
    NSLog(@"--------------------------------");
    _index = index;
    static NSString *kPageID = @"numberPageID";
    JCFlipPage *page = [flipPageView dequeueReusablePageWithReuseIdentifier:kPageID];
     NSLog(@"%@---%lu",page,(unsigned long)index);
    page.whlabel.text = @"";
    [page.whlabel sizeToFit];
    if (!page)
    {
        
        
        page = [[JCFlipPage alloc] initWithFrame:flipPageView.bounds reuseIdentifier:kPageID];
        NSLog(@"%@---%lu",page,(unsigned long)index);
        page.whlabel.text = @"我是假的";
        [page.whlabel sizeToFit];
        
    }else{}
    
    if (index%3 == 0)
    {
        page.backgroundColor = [UIColor blueColor];
    }
    else if (index%3 == 1)
    {
        page.backgroundColor = [UIColor greenColor];
    }
    else if (index%3 == 2)
    {
        page.backgroundColor = [UIColor redColor];
    }else{}
    
    page.tempContentLabel.text = [NSString stringWithFormat:@"%lu", (unsigned long)index];
    //    for (int j = 0; j < 500; j++)
    //    {
    //        page.tempContentLabel.text = [NSString stringWithFormat:@"%@ %d", page.tempContentLabel.text, index];
    //    }
    
    return page;
}


@end
